//
//  STDSAttrib.hpp
//  STDRenderSDK
//
//  Created by 陈学明 on 2023/3/13.
//

#ifndef STDSAttrib_hpp
#define STDSAttrib_hpp

#include <stdio.h>
#include "Basic/graphic/STDSOpenGL.h"
#include "Basic/graphic/STDSGLFunctions.hpp"

class STDSAttrib {
    
public:
    STDSAttrib() {

    }

    virtual ~STDSAttrib() {
        _release();
    }

    virtual void draw();

public:
    inline void useIdx(bool _use){
        if(_use == mUseIdx)
            return;
        mUseIdx = _use;
        mDirtyIdx = true;
        _reset();
    }

    inline void useTex(bool _use){
        if(_use == mUseTex)
            return;
        mUseTex = _use;
        mDirtyTex = true;
        _reset();
    }

    inline void useClr(bool _use){
        if(_use == mUseClr)
            return;
        mUseClr = _use;
        mDirtyClr = true;
        _reset();
    }

    inline void setDepth(float _dep){
        mDepth = _dep;
        _reset();
    }

    inline void setPosVex(int _pos) {
        mPosVex = _pos;
    }

    inline void setPosTex(int _pos) {
        mPosTex = _pos;
    }

    inline void setPosParam(int _pos) {
        mPosParam = _pos;
    }

    inline void setPosClr(int _pos) {
        mPosClr = _pos;
    }

    // 边角定位
    inline void setPosVex_Corner(int _pos) {
        mPosVex = _pos;
    }

    inline float getDepth(){
        return mDepth;
    }

    inline float *getArrVex(){
        return mArrVex;
    }

    inline int getCountVertices(){
        return mCountVertices;
    }

public:
    virtual void setVertices2D(int _count, float *_vex) {}

//    virtual void setVertices2D(GxBasic::GxArrPoint2F *_arr) {}
//
//    virtual void setVertices2D(GxBasic::GxArrPoint3F *_arr) {}
//
//    virtual void setVertices3D(GxBasic::GxArrPoint3F *_arr, bool _useInputDepth) {}

    virtual void setTexCoords(int _count, float *_tex) {}

    virtual void setColors(int _count, float *_clr) {}

    virtual void setParam4(float *_params) {}

protected:
    virtual void _init() {

    }

    void _reset();

    void _release();

    virtual void _resetCount() {};

    virtual void _resetDrawFunc() {};

    virtual void _resetIdx() {};

    virtual void _resetVex() {};

    virtual void _resetTex() {};

    virtual void _resetClr() {};

protected:
    typedef void (*pDrawFunc)(void *_idx, int _count, int _start);

    pDrawFunc mDrawFunc;

    int mCountVertices{0};     // 顶点数量
    int mCountParticle{0};     // 元素数量
    int mPosVex{-1};
    int mPosTex{-1};
    int mPosParam{-1};
    int mPosClr{-1};

    float mDepth{0.f};

    bool mUseIdx{false};
    bool mUseTex{false};
    bool mUseClr{false};

    bool mDirtyIdx{false};
    bool mDirtyVex{true};
    bool mDirtyTex{false};
    bool mDirtyClr{false};

    uint16_t *mArrIdx{nullptr};
    float *mArrVex{nullptr};
    float *mArrParam{nullptr};
    float *mArrTex{nullptr};
    float *mArrClr{nullptr};

    unsigned int mVAO{0};
    unsigned int mVBO{0};
    unsigned int mVBOParam{0};
};

#endif /* Attrib_hpp */
